package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ReflectDemo6 {
    public static void main(String[] args) throws  Exception{
        Class cls = Class.forName("reflect.Person");
        Method method1 = cls.getMethod("say", String.class,int.class);
        String name = method1.getName();
        System.out.println("方法名是："+name);
        Class[] paramTypes = method1.getParameterTypes();
        for (Class paramType : paramTypes){
            System.out.println("参数类型是："+paramType.getName());
        }
        int count = method1.getParameterCount();
        System.out.println("方法一共有："+count+"个参数");

        Class returnType = method1.getReturnType();
        System.out.println("返回值类型为："+returnType.getName());
        int modifiers = method1.getModifiers();
        switch (modifiers){
            case Modifier.PUBLIC:
                System.out.println("public");
                break;
            case Modifier.PRIVATE:
                System.out.println("private");
                break;
            case Modifier.PROTECTED:
                System.out.println("protected");
                break;
            default:
                System.out.println("default");
                break;

        }
    }
}
